const { verify } = require('../utils/tools')

const auth = (req, res, next) => {
  res.set('Content-Type', 'application/json;charset=utf-8')

  let token = req.headers['x-access-token']

  let decoded = verify(token)

  if (decoded) {
    next()
  } else {
    res.render('fail', {
      data: JSON.stringify({
        msg: '请登录.'
      })
    })
  }
}

module.exports = {
  auth
}